package com.zhuss.repair.db.dao.ext;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.zhuss.bean.bo.repair.repair.SearchRepairBo;
import com.zhuss.bean.bo.repair.repairAudit.ChaKanBo;
import com.zhuss.bean.vo.food.food.DetailFoodVo;
import com.zhuss.bean.vo.repair.repair.DetailRepairVo;
import com.zhuss.bean.vo.repair.repair.ListRepairVo;
import com.zhuss.repair.db.dao.gen.RepairMapper;
import com.zhuss.repair.db.entity.ChaKan_DengJi;
import com.zhuss.repair.db.entity.ChaKan_HeCha;
import com.zhuss.repair.db.entity.ChaKan_KanCha;
import com.zhuss.repair.db.entity.ChaKan_PaiDan;
import com.zhuss.repair.db.entity.ChaKan_PingJia;
import com.zhuss.repair.db.entity.ChaKan_WeiXiu;
import com.zhuss.repair.db.entity.Goods;
import com.zhuss.repair.db.entity.Repair;
import com.zhuss.repair.db.entity.WeiXiuDanVo;

@Mapper
public interface RepairDao extends RepairMapper {
	
	List<Repair> listAll(@Param("area") Integer area, @Param("status") Integer status);

	/*List<ListRepairVo> list(SearchRepairBo bo);
	
	Integer countList(SearchRepairBo bo);*/

	/*DetailFoodVo detail(@Param("foodId") Long foodId);*/
	
	List<Repair> listByName(@Param("name") String name, @Param("area") Integer area);

	
	
	
	
	//删除
	@Update("UPDATE t_repair SET status = -1 WHERE id = #{id}")
	void delete(Repair record);
	
	void create(Repair record);
	
	//获取当天流水编号
	@Select("SELECT (count(id)+1) as count from t_repair where create_time BETWEEN CONCAT(CURDATE(),' 00:00:00') AND CONCAT(CURDATE(),' 23:59:59')")
	Integer getNowNo();
	
	//退回
	@Update("UPDATE t_repair SET step = 1, audit = 0 WHERE id = #{id}")
	void back(Repair record);
	
	DetailRepairVo detail(Integer id);
	
	List<ListRepairVo> list(SearchRepairBo bo);
	
	Integer countList(SearchRepairBo bo);

	
	
	ChaKan_DengJi getChaKan_DengJi(Map<String, Object> map);

	ChaKan_PaiDan getChaKan_PaiDan(Map<String, Object> map);

	ChaKan_KanCha getChaKan_KanCha(Map<String, Object> map);

	@Select("SELECT (select value from t_config where type='RepairGoods' and config_key=g.goods_key limit 1) as goodsName,g.goods_count as goodsCount from t_repair_goods g where g.repair_id=#{repair_id}")
	List<Goods> getKanCha_Goods(Map<String, Object> map);

	ChaKan_WeiXiu getChaKan_WeiXiu(Map<String, Object> map);

	
	ChaKan_HeCha getChaKan_HeCha(Map<String, Object> map);

	ChaKan_PingJia getChaKan_PingJia(Map<String, Object> map);

	WeiXiuDanVo getWeiXiuDan(Map<String,Object> map);

	@Select("SELECT name from t_company where company_id = (SELECT company_id from t_user where user_id = #{value}) limit 1")
	String getCompanyNameByUserId(Integer userId);
	
	@Select("SELECT company_id from t_company where company_id = (SELECT company_id from t_user where user_id = #{value}) limit 1")
	Integer getCompanyIdByUserId(Integer userId);
	
    
}